package com.miplus.ccrm.report.controller;

import com.miplus.ccrm.common.CmdResVo;
import com.miplus.ccrm.common.JSysUser;
import com.miplus.ccrm.common.PageData;
import com.miplus.ccrm.common.R;
import com.miplus.ccrm.report.controller.vo.cti.*;
import com.miplus.ccrm.report.controller.vo.ivr.listAgentCallVO;
import com.miplus.ccrm.report.controller.vo.rep.*;
import com.miplus.ccrm.report.controller.vo.robot.CallStatsVo;
import com.miplus.ccrm.report.security.JCommonData;
import com.miplus.ccrm.report.service.cti.AspectReportService;
import com.miplus.ccrm.report.service.cti.ReportCallHistService;
import com.miplus.ccrm.report.service.cti.TRecorderService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 3-3.CTI报表数据接口
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/call")
public class CallController {
    @Resource
    private JCommonData jCommonData;

    @Resource
    private TRecorderService tRecorderService;

    @Resource
    private ReportCallHistService reportCallHistService;
    @Resource
    private AspectReportService aspectReportService;

    /**
     * 取录音历史LIST
     */
    @GetMapping("/callHistList")
    public R<PageData<CallResVo>> callHistList(@Validated CallReqVo callReqVo){
        JSysUser user= jCommonData.getCurrUsr();
        return R.SuccessPage(tRecorderService.recordList(user,callReqVo));
    }
    /**
     * 呼叫明细历史list
     */
    @PostMapping("/listAgentCall")
    public R<PageData<listAgentCallVO>> listAgentCall(@RequestBody listAgReqCallVo reqCallVO) {
        //String usrid= jCommonData.getCurrUsrID();
        return R.SuccessPage(reportCallHistService.listAgentCall(reqCallVO));
    }
    /**
     * 录音历史导出
     */
    @PostMapping("/expRecordList")
    public R<CmdResVo> expRecordList(@RequestBody @Validated CallReqVo callReqVo, HttpServletResponse response){
        JSysUser user= jCommonData.getCurrUsr();
        return R.Success(tRecorderService.expRecordList(user,callReqVo,response));
    }
    /**
     * 呼叫明细历史导出
     */
    @PostMapping("/expReportList")
    public R<CmdResVo> expRecordList(@RequestBody listAgReqCallVo reqCallVO, HttpServletResponse response){
        //String usrid= jCommonData.getCurrUsrID();
        return R.Success(reportCallHistService.expReportCallList(reqCallVO,response));
    }

    /**
     * 坐席呼叫统计日报
     */
    @GetMapping("/repAgentCallDay")
    public R<PageData<CallAgDayResVo>> repAgentCallDay(@Validated CallAgDayReqVo callReqVo){
        String usrid= jCommonData.getCurrUsrID();
        return R.SuccessPage(reportCallHistService.repAgentCallDay(usrid,callReqVo));
    }


    /**
     * 机器人呼叫统计按(日,月，年)统计，最后求和
     */
    @PostMapping("/repRobotCallDay")
    public R<PageData<CallStatsVo>> repRobotCallDay(@RequestBody CallStatsReqVo callStatsReqVo){
        //String usrid= jCommonData.getCurrUsrID();
        return R.SuccessPage(reportCallHistService.repRobotCallDay(callStatsReqVo));
    }

    /**
     * 机器人统计报表导出
     */
    @PostMapping("/expRobotCallDay")
    public R<CmdResVo> expRobotCallDay(@RequestBody CallStatsReqVo callStatsReqVo, HttpServletResponse response){
        //String usrid= jCommonData.getCurrUsrID();
        return R.Success(reportCallHistService.expRobotCallDay(callStatsReqVo,response));
    }
    /**
     * 坐席呼叫统计日报导出
     */
    @PostMapping("/expAgentCallDay")
    public R<CmdResVo> expAgentCallDay(@RequestBody @Validated CallAgDayReqVo callReqVo, HttpServletResponse response){
        String usrid= jCommonData.getCurrUsrID();
        return R.Success(reportCallHistService.expAgentCallDay(usrid,callReqVo,response));
    }

    /**
     * 取坐席录音翻译对话List
     */
    @GetMapping("/quyAgentDialogue")
    public R<List<DialogueResVo>> quyAgentDialogue(@Validated DialogueReqVo reqVo){
        return R.Success(tRecorderService.quyAgentDialogue(reqVo.getCallid(),reqVo.getAgentid()));
    }

    /**
     * 取机Ivr翻译对话List
     */
    @GetMapping("/quyIvrDialogue")
    public R<List<DialogueResVo>> quyIvrDialogue(@RequestParam @NotNull String callid){
        return R.Success(tRecorderService.quyIvrDialogue(callid));
    }
    /**
     * ACD组统计报表按日
     */
    @PostMapping("/repAcdCallDay")
    public R<PageData<AcdResVo>> repRobotCallDay(@RequestBody AcdReqVo acdReqvo){
        //String usrid= jCommonData.getCurrUsrID();
        return R.SuccessPage(reportCallHistService.repAcdCallDay(acdReqvo));
    }
    /**
     * ACD统计日报导出
     */
    @PostMapping("/expAcdCallDay")
    public R<CmdResVo> expAcdCallDay(@RequestBody AcdReqVo acdReqvo, HttpServletResponse response){
        //String usrid= jCommonData.getCurrUsrID();
        return R.Success(reportCallHistService.expAcdCallDay(acdReqvo,response));
    }

    /**
     * 通话统计报表
     */
    @PostMapping("/repCallStatistics")
    public R<PageData<CallStatisticsResVo>> repCallStatistics(@RequestBody CallStatisticsReqVo callStatisticsReqVo){
        return R.SuccessPage(reportCallHistService.repCallStatistics(callStatisticsReqVo));
    }
    /**
     * 通话统计报表导出
     */
    @PostMapping("/expCallStatistics")
    public R<CmdResVo> expCallStatistics(@RequestBody CallStatisticsReqVo callStatisticsReqVo, HttpServletResponse response){
        return R.Success(reportCallHistService.expCallStatistics(callStatisticsReqVo,response));
    }
    /**
     * 获取手机号码归属地
     */
    @GetMapping("/getPhoneArea")
    public R<String> getPhoneArea(@RequestParam("phone") String phone) {
        return R.Success(aspectReportService.getPhoneArea(phone));
    }

    /**
     * 呼叫归属地统计报表(按统计时间分组)
     */
    @PostMapping("/statisticsByTimeRange")
    public R<PageData<AreaStatisticResVo>> statisticsByTimeRange(@RequestBody AreaStatisticReqVo paras){
        return R.SuccessPage(reportCallHistService.statisticsByTimeRange(paras));
    }

    /**
     * 呼叫趋势
     */
    @PostMapping("/queryCallInTrend")
    public R<List<CallInTrendResVo>> queryCallInTrend(@RequestBody CallInTrendReqVo paras){
        return R.Success(reportCallHistService.queryCallInTrend(paras));
    }
    /**
     * 呼叫趋势报表导出
     */
    @PostMapping("/expCallInTrend")
    public R<CmdResVo> expCallInTrend(@RequestBody CallInTrendReqVo paras, HttpServletResponse response){
        return R.Success(reportCallHistService.expCallInTrend(paras,response));
    }

}
